# -*- coding: utf-8 -*-
# !/usr/bin/env python
# @ author = 'zoushunli'
# @ author_email = '409358374@qq.com'
import os

import requests
import random
import bs4
from multiprocessing import Pool
import scrapy
import re
import sqlite3
import xlwt
from lxml import etree

[{'BB': {'A': 11, 'B': 22}},
 {'CC': {'A': 33, 'B': 44}}
 
 ]









html_doc ="""
<html>
<head></head>
    <body>
        <li>
            <a href="/book_16860.html" title="总裁的新鲜小妻">
                <img src="/16860s.jpg">
            </a>
                <img src="/kukuku/images/only.png" class="topss png_bg">
                <img src="abc.png" class="topss png_bg">
            <a href="/book_16860.html">总裁的新鲜小妻子</a>
        </li>
        <li>
            <a href="/book_16861.html" title="斗神天下">
                <img src="/16861s.jpg">
            </a>
                <img src="/kukuku/images/only.png" class="topss png_bg">
                <img src="def.png" class="topss png_bg">
            <a href="/book_16861.html">斗神天下</a>
        </li>
    
    </body>
</html>
"""




class temp(object):
    def __init__(self):
        super(temp, self).__init__()
        self.user_agent = [
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0']
        self.headers = {'User-Agent': random.choice(self.user_agent), 'Accept-Encoding': 'gzip, deflate',
                        'Accept': '*/*', 'Connection': 'keep-alive', 'Accept-Language': 'en-US,en;q=0.5'}

        self.re_compile = re.compile
        self.requests_get = requests.get
        self.bs4_BeautifulSoup = bs4.BeautifulSoup
        self.xlwt_Workbook = xlwt.Workbook
        self.sqlite3_connect = sqlite3.connect
        
        
        
    def get_cookies(self, url):
        session = requests.Session()
        data = session.get(url, headers=self.headers)
        print(data)
        print('=='*30)
        print(data.cookies)
        
    def get_html_text(self, url):
        
        html = ''
        try:
            r = self.requests_get(url, headers=self.headers, timeout=10)
            r.status_code
            r.encoding = r.apparent_encoding
            # html = r.content.decode('utf-8')
            html = r.content
        except Exception as e:
            print('Exception:-->', e)
            print("产生异常")
        finally:
            # print(html)
            return html
    
    def prase_html_data(self, html_text, data_list):
        selector = etree.HTML(html_text)
        demo = selector.xpath('//a')
        for d in demo:
            title = d.xpath('@title')
            print(title)
            
    
    def save_html_data_2_xlwt(self, data_list, path=None):
        pass
    
    def create_table(self, table_name, db_path):
        pass
    
    def insert_data(self, data_list, db_path):
        pass
    
    def save_html_data_2_sqlite(self, table_name, data_list, db_path):
        pass
    
    def download_img(self, data_list):
        pass
""":
Set-Cookie: gitee-session-n=a05YR2dWa0VNU3IwdDhTOHZrYWM5ZENITTVIdlArQTdGNFVoZVBWN0F6bENhb3hVbmtGSVE4bFQvMnpQMVh2ekdjUEJTWnpmQk1VK29LOElhOEovUjlkMnFqT0VXa0pwZi9hOTBxczhTMThjbXFYZUxZdzFrNFFibFY5QnpVUXRmdVZNS0UvVUFzRmNTSnplOVdURFpIbG92QS84dFZLYi82Z0dLSmJMcTJFMmNGYk0rcUlTV3ZzZTQ2Kzd5RS9aLS1oYVNCbVRLay9oK09DSWxSSDI0c0xRPT0%3D--09d28e2cd3d3de7332b13c21d43aa723e23f35bb; domain=.gitee.com; path=/; HttpOnly



"""

def fact(n):
    return fact_iter(n, 1)

def fact_iter(num, product):
    if num == 1:
        return product
    return fact_iter(num - 1, num * product)

def main():
    db_path = 'temp.db'
    table_name = 'temp'
    url = 'https://www.baidu.com/'
    list_data = list()
    demo = temp()
    html_data = demo.get_html_text(url)
    # print(html_data.header)
    # demo.get_cookies(url)
    # demo.prase_html_data(html_doc, list_data)
def move(n, a, b, c):
    if n == 1:
        print('move', a, '-->', c)
    else:
        move(n-1, a, c, b)
        move(1, a, b, c)
        move(n-1, b, a, c)



if __name__ == "__main__":
    # move(4, 'A', 'B', 'C')
    main()

        




